<div style="margin: 5em; margin-left: 10em;">
<code>
<?php

require_once 'smtp.php';
require_once 'letter.php';

$toKey = '';
$toValue = 'philonov@gmail.com';
$fromKey = '';
$fromValue = 'rep@shop4you.com.ua';
$subject = 'test';
$message = 'asdjkfh sdhfjk sfjkh asdfjsadkfjsa  fkjasf hasfjkhsadf';
$type = 'text/html';
$encode = 'Windows-1251';

class DrawMessage
{
    protected $_M_start;

    function __construct()
    {
        $this->_M_start = microtime(true);
    }

    protected function sys_char($char)
    {
        /*#x' . sprintf('%X', $char) . '*/
        return '<span style="background-color: #C0C0C0;">&nbsp;</span>';
    }

    protected function strHTML($str)
    {

        $eol    = ord("\n");
        /*$lt     = ord('<');
        $gt     = ord('>');
        $amp    = ord('&');
        $quot   = ord('"');
        $apos   = ord("'");
        */
        $out = '';
        for ($i = 0; $i < strlen($str); $i++) {
            $chr = ord($str[$i]);
            if ($chr >= 32) {
                $out .= htmlspecialchars($str[$i], ENT_QUOTES);
            } else {
                if ($chr == $eol) {
                    $out .= '<br />';
                } else {
                    $out .= $this->sys_char($chr);
                }
            }
        }
        return $out;
    }

    function msgHTML($msg)
    {
        $id = ' id="' . round(($msg->time() - $this->_M_start), 3) . ' sec"';
        $color = is_a($msg, 'ResponseMessage') ? '#DE5F15' : '#4886C5';
        echo '<span' . $id . ' style="color: ' . $color . ';">' . $this->strHTML($msg->value()) . '</span>';
    }
}

$messager = new DrawMessage();

try {
    $params = SocketParams("shop4you.com.ua", 25);
    $params->OnMessageEvent(array($messager, 'msgHTML'));

    $smtp = new SMTPClient($params);

    $smtp->timeout_read_or_write(TimeOut(1));

    $smtp->get();

    $smtp->ehlo('dual2');

    $smtp->mail($fromValue);

    $smtp->rcpt($toValue);

    $smtp->data();

    $letter = new LetterEnvilope();
    $letter->subject($subject);
    $letter->from($fromValue);
    $letter->to($toValue);
    $letter->x_sender($fromValue);
    $letter->return_path($fromValue);
    $letter->errors_to($fromValue);
    $letter->x_mailer($fromValue);
    $letter->x_priority(3);
    $letter->content_type($type, $encode);
    $letter->letter($message);
    foreach ( $letter->data() as $line ) {
        $smtp->msg_line($line);
        $smtp->rset();
        break;
    }

    $smtp->end_data();

    $smtp->rset();

    $smtp->quit();

} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage();
}

?>
</code>
</div>